function validate(){
	var user = document.forms[0].user.value;
	var pswd = document.forms[0].pswd.value;
	var code = document.forms[0].code.value;
	var url  = document.forms[0].url.value;
	var valiRegExp = new RegExp("^[0-9]+");

	if (!valiRegExp.test(user) || user.length < 5){
		alert('请正确输入K秀帐号！');
	  	document.forms[0].user.focus();
    	document.forms[0].user.select();
		return false;
	}else if (pswd == '' || pswd.length < 6) {
		alert('请正确输入登录密码！');
		document.forms[0].pswd.focus();
		document.forms[0].pswd.select();
		return false;
	}else if (!valiRegExp.test(code)) {
		alert('请正确输入登录校验码！');
		document.forms[0].code.focus();
		document.forms[0].code.select();
		return false;
	}else {
		document.forms[0].btnSubmit.disabled = true;
		
		if (window.XMLHttpRequest){
			var  xmlhttp = new XMLHttpRequest();
	    }else if (window.ActiveXObject) {
			var  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	    }

		method = 'POST';
	  	var process_url = 'index.php?controller=login&action=check';
		var postdata = 'code=' + code + '&user=' + user + '&pswd=' + pswd;
		
		xmlhttp.onreadystatechange = function()
		{
			var result = false;
	        if (xmlhttp.readyState == 4)
			{
				if (xmlhttp.status == 200)
				{
					result = xmlhttp.responseText;
					//alert(result);
					if(result == '100'){
						var logPlace = document.getElementById('logPlace');
						var URI = '';
						if (url == ''){
							URI="index.php";
						}else{
							URI = url;
						}
						logPlace.innerHTML = "<p align='center' style='font-size:14px;color:blue;'>  欢迎 <b>"+user+"</b> 来到K秀首页!</p>"
						  + "如果您的浏览器不支持跳转, 请直接 <a href='"+URI+"'>点击这里</a>.";
						window.location.href=URI;
					}
					else if(result == '101')
					{
						alert('[提示]：登录校验码错误！请重新输入。');
						fresh_code();
					    document.forms[0].code.focus();
						document.forms[0].code.select();
						document.forms[0].btnSubmit.disabled = false;
					}
					else if(result == '102')
					{
						alert('[提示]：K秀帐号或登录密码错误！请重新输入。');
						fresh_code();
					    document.forms[0].pswd.focus();
					    document.forms[0].pswd.select();
						document.forms[0].btnSubmit.disabled = false;
					}
					else
					{
						alert('[提示]：系统繁忙，请稍后再试！#msg 001');
						document.forms[0].btnSubmit.disabled = false;
					}
				}
				else
				{
					alert('[提示]：系统繁忙，请稍后再试！#msg 002');
					document.forms[0].btnSubmit.disabled = false;
				}
		    }
	    }
			xmlhttp.open(method,process_url,true);
			xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xmlhttp.send(postdata);
	    return false;
		/*document.forms[0].action = url;
		document.forms[0].submit();*/
	}

	return false;
}

function fresh_code(){
	document.getElementById('checkcode').src = "checkcode.inc.php?id="+Math.random();
}

function key_board(strObj)
{
	var objInput = document.all(strObj);
	if(objInput)
	{
		var intLeft = 100+Math.random()*400;
		var intTop	= 100+Math.random()*300;
		while(intLeft>(screen.width-282))
		{
			intLeft = 100+Math.random()*400;
		}
		while(intLeft>(screen.width-95))
		{
			intTop = 100+Math.random()*300;
		}

		var strUrl   = 'keyborad.html';
		var strStyle = 'dialogLeft='+intLeft+'pt;dialogTop='+intTop+'pt;dialogWidth=282pt;dialogHeight=95pt;center=no;resizable=no;status=off;help=off;'
		var strDate  = objInput.value;
		var strData  = window.showModalDialog(strUrl, objInput, strStyle);
	}
}